//
//  PBMyHeaderCell.m
//  PBHomeDemo
//
//  Created by Playboy on 2017/12/20.
//  Copyright © 2017年 tmkj. All rights reserved.
//

#import "PBMyHeaderCell.h"
#import "LCActionSheet.h"
#import "PBMyInfoController.h"
#import "PBMyDeputeController.h"
#import "PBMyOrderController.h"
#import "PBMyContractController.h"
#import "PBAboutMeController.h"
#import "PBMyAccountController.h"
#import "PBMySeriveController.h"

@interface PBMyHeaderCell ()

@property (strong, nonatomic) IBOutlet UIImageView *headerImageView;
@property (strong, nonatomic) IBOutlet UILabel *nickNameLabel;
@property (strong, nonatomic) IBOutlet UIView *oneView;
@property (strong, nonatomic) IBOutlet UIView *orderView;
@property (strong, nonatomic) IBOutlet UIView *hetongView;
@property (strong, nonatomic) IBOutlet UIView *weituoView;
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *topConstraint;
@property (strong, nonatomic) IBOutlet UIView *setView;
@property (strong, nonatomic) IBOutlet UIImageView *writeImageView;
@property (weak, nonatomic) IBOutlet UIView *accountView;
@property (weak, nonatomic) IBOutlet UIView *seriveView;
@property (weak, nonatomic) IBOutlet UIView *aboutView;
@property (nonatomic, strong) PBMyInfoModel *model;

@end

@implementation PBMyHeaderCell

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
    if (IS_IPHONE_X) {
        self.topConstraint.constant = -44;
    }else {
        self.topConstraint.constant = -22;
    }
    UITapGestureRecognizer *headerTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(headerTapMethod)];
    self.headerImageView.userInteractionEnabled = YES;
    [self.headerImageView addGestureRecognizer:headerTap];
    self.headerImageView.layer.borderWidth = 2.0f;
    self.headerImageView.layer.borderColor = [UIColor whiteColor].CGColor;
    [self addTapMethod];
}

- (void)addTapMethod {
    UITapGestureRecognizer *oneTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(oneTapMethod)];
    [self.oneView addGestureRecognizer:oneTap];
    UITapGestureRecognizer *orderTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(orderTapMethod)];
    [self.orderView addGestureRecognizer:orderTap];
    UITapGestureRecognizer *hetongTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(hetongTapMethod)];
    [self.hetongView addGestureRecognizer:hetongTap];
    UITapGestureRecognizer *setTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(setTapMethod)];
    [self.setView addGestureRecognizer:setTap];
    UITapGestureRecognizer *loginTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(loginTapMethod)];
    [self.nickNameLabel addGestureRecognizer:loginTap];
    UITapGestureRecognizer *accountTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(accountTapMethod)];
    [self.accountView addGestureRecognizer:accountTap];
    UITapGestureRecognizer *seriveTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(seriveTapMethod)];
    [self.seriveView addGestureRecognizer:seriveTap];
    UITapGestureRecognizer *aboutTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(aboutTapMethod)];
    [self.aboutView addGestureRecognizer:aboutTap];
}

- (void)oneTapMethod {
    if (self.model) {
        PBMyDeputeController *vc = [[PBMyDeputeController alloc] init];
        vc.hidesBottomBarWhenPushed = YES;
        [self.jumpVC.navigationController pushViewController:vc animated:YES];
    }else {
        [self loginTapMethod];
    }
}
- (void)orderTapMethod {
    if (self.model) {
        PBMyOrderController *vc = [[PBMyOrderController alloc] init];
        vc.hidesBottomBarWhenPushed = YES;
        [self.jumpVC.navigationController pushViewController:vc animated:YES];
    }else {
        [self loginTapMethod];
    }
}
- (void)hetongTapMethod {
    if (self.model) {
        PBMyContractController *vc = [[PBMyContractController alloc] init];
        vc.hidesBottomBarWhenPushed = YES;
        [self.jumpVC.navigationController pushViewController:vc animated:YES];
    }else {
        [self loginTapMethod];
    }
}

- (void)setTapMethod {
    [self headerTapMethod];
}

- (void)accountTapMethod {
    if (self.model) {
        PBMyAccountController *vc = [[PBMyAccountController alloc] init];
        vc.hidesBottomBarWhenPushed = YES;
        [self.jumpVC.navigationController pushViewController:vc animated:YES];
    }else {
        [self loginTapMethod];
    }
}

- (void)seriveTapMethod {
    if (self.model) {
        PBMySeriveController *vc = [[PBMySeriveController alloc] init];
        vc.hidesBottomBarWhenPushed = YES;
        [self.jumpVC.navigationController pushViewController:vc animated:YES];
    }else {
        [self loginTapMethod];
    }
}

- (void)aboutTapMethod {
    if (self.model) {
        PBAboutMeController *vc = [[PBAboutMeController alloc] init];
        vc.hidesBottomBarWhenPushed = YES;
        [self.jumpVC.navigationController pushViewController:vc animated:YES];
    }else {
        [self loginTapMethod];
    }
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

- (void)refreshWithModel:(PBMyInfoModel *)model {
    self.model = model;
    if (model) {
        [self.headerImageView sd_setImageWithURL:[NSURL URLWithString:model.avatar] placeholderImage:[UIImage imageNamed:@"my_header"]];
        self.nickNameLabel.text = model.nickname;
        self.writeImageView.hidden = NO;
        self.nickNameLabel.userInteractionEnabled = NO;
    }else {
        self.nickNameLabel.text = @"登录/注册";
        self.headerImageView.image = [UIImage imageNamed:@"my_header"];
        self.writeImageView.hidden = YES;
        self.nickNameLabel.userInteractionEnabled = YES;
    }
}

- (void)loginTapMethod {
    PBLoginViewController *login = [[PBLoginViewController alloc] init];
    login.hidesBottomBarWhenPushed = YES;
    [self.jumpVC.navigationController pushViewController:login animated:YES];
}

- (void)headerTapMethod {
    if (self.model) {
        PBMyInfoController *vc = [[PBMyInfoController alloc] init];
        vc.hidesBottomBarWhenPushed = YES;
        [self.jumpVC.navigationController pushViewController:vc animated:YES];
    }else {
        [self loginTapMethod];
    }
}

@end
